
<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field v-model="hotel.name" label="名称" 
        :rules="[{ required: true, message: '请填写名称' }]"/>
          <van-row>
      <van-col span="14">
        <select-area @selectedArea="selectedArea" />
      </van-col>
      <van-col span="10">
        <select-type @selectedType="selectedType" objectName="wh_hotel" fieldName="mode"/>
      </van-col>
    </van-row>  
      
      <van-field
        v-model="hotel.addr" type="text" label="地址" 
        :rules="[{ required: true, message: '请填写地址' }]"/>
      <van-field
        v-model="hotel.room_num" type="digit" label="房间数量" 
        :rules="[{ required: true, message: '请填写数量' }]"/>
      <van-field
        v-model="hotel.checkin_num" type="digit" label="已住人数" 
        :rules="[{ required: true, message: '请填写人数' }]"/>
      <van-field
        v-model="hotel.conn_person"  label="联系人" 
        :rules="[{ required: true, message: '请填写联系人' }]"/>
      <van-field
        v-model="hotel.conn_phone" type="digit" label="联系电话" 
        :rules="[{ required: true, message: '请填写电话' }]"/>
      <van-field
        v-model="hotel.conn_weixin" label="微信" 
        :rules="[{ required: true, message: '请填写微信' }]"/>
      <van-field
        v-model="hotel.remark"  label="备注" 
        :rules="[{ required: false, message: '请填写备注' }]"/>
      <van-button round block type="info" native-type="submit">提交</van-button>
    </van-form>
  </div>
</template>

<script>
  import { insert } from "@/api/common";
  import SelectArea from "../components/SelectArea";
  import SelectType from "../components/SelectType";
  import { Toast } from 'vant';

  export default {
    name: "freestay",
    components: {
      SelectArea,
      SelectType,
    },
    data() {
      return {
        items: [],
        areaValue: 0,
        typeValue: 0,
        hotel: {name:'',addr:'',mode:'',
          checkin_num:'',checkin_area:'',
          conn_person:'',conn_phone:'',conn_weixin:'',remark:''},
      }
    },
    mounted() {
    },
    methods: {
      onSubmit(values) {
        if(this.areaValue==0||this.typeValue==0) {
          Toast('请选择区域和类型');
          return;
        }
        this.hotel.checkin_area = this.areaValue;
        this.hotel.mode = this.typeValue;
        var params={
          'Wh_hotel': this.hotel,
          'tag': 'Wh_hotel'
        }
        let that = this;
        insert(params)
          .then((res) => {
            if(res.data.msg=='success')
              Toast.success('保存房源成功');
            else
              Toast.fail('保存房源失败');
          })
          .catch(function (error){
              Toast.fail('调用服务器，保存房源失败');
          });
      },
      selectedArea(value) {
        this.areaValue = value;
      },
      selectedType(value) {
        this.typeValue = value;
      },
      // 调用api获得列表
      getLists(){
        let params={
            '[]': {
                'TableName': {'@column': 'id,name'}
            }
        };
        get(params)
          .then( res=> {
            this.items = res.data["[]"];
          })
          .catch(function (error){
              console.log(error);
          });
      },
    }
  }
</script>

<style scoped>

</style>
  